const requestAgain = ({url, data = {}, method = 'GET', header = {}}) => {
	
	const baseUrl = import.meta.env.MODE==='development' ? 'http://localhost:8002' : 'https://www.baidu.com'
	const token = uni.getStorageSync('token')
	const realHeader = token ? {...header, token: token} : header
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '请求中...'
		})
		uni.request({
			url: baseUrl + url,
			method,
			data,
			header: realHeader,
			success(res) {
				if(res.statusCode === 200) {
					// {code: 1234} => {data: {code: 1234}}
					resolve(res.data)
				} else {
					reject('服务器异常')
					uni.$u.toast('服务器异常')
				}
				uni.hideLoading()
			},
			fail(err) {
				reject(err)
				uni.$u.toast('服务器异常')
				uni.hideLoading()
			}
		})
	})
	
	
	
	
	
}

export default requestAgain